/*
 * @lc app=leetcode.cn id=131 lang=javascript
 *
 * [131] 分割回文串
 */

// @lc code=start
var isPalindrome = function (s) {
  return s === s.split('').reverse().join('');
}

var partitionPath = function (s, path, result) {
  for (let i = 1; i <= s.length; i++) {
    const str = s.slice(0, i);
    if (isPalindrome(str)) {
      path.push(str);
      if (i === s.length) {
        result.push([...path]);
      } else {
        partitionPath(s.slice(i), path, result);
      }
      path.pop()
    }
  }
}
/**
 * @param {string} s
 * @return {string[][]}
 */
var partition = function (s) {
  const result = [];
  const path = [];
  partitionPath(s, path, result);
  return result;
};

// @lc code=end

